<?php

/**
 * Sample object - sample object
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class SampleObject extends Erra_Fields_Base_Object {

    function __construct($objectId, $buildArgs = null) {
        parent::__construct($objectId, $buildArgs);
        // TODO : multiple radio, multiple checkbox

        $text_field = Erra_Fields_Text::create('text_field')
                ->setDescription('Some text field')
                ->setSize(70);

        $wysiwyg = Erra_Fields_Wysiwyg::create('wysiwyg_field')
                ->setDescription('Some wysiwyg field');

        $image_field = Erra_Fields_Image::create('image_field')
                ->setDescription('image')
                ->setWidth(300)
                ->setHelp('You can add png or jpg image')
                ->setInAdminList(true);

        $combo = Erra_Fields_ComboBox::create('create_combo')
                ->setDescription('Votre DJ préféré')
                ->setHelp('Choose best DJ in the list')
                ->setInAdminList(true)
                ->fill(array('_' => 'Indifférent', 'guetta' => 'David Guetta', 'sinclar' => 'Bob Sinclar'));

        $combo_fitler = $combo->createTextSearch()
                ->setDescription('Tri par artiste')
                ->setOperator('=?');


        $this->addFields($text_field, $wysiwyg, $image_field, $combo, $combo_fitler);
        $this->setDescription('A simple object example');
    }

    public function __render_list($displayArgs = null) {
        $res = '';
        $elements = $this->getObjectArray();
        foreach ($elements as $element) {
            $res .= 'Titre : <i>' . $element->text_field->value . '</i><br/>';
            $images = $element->image_field->getAllInstances();
            foreach ($images as $image) {
                if (strlen($image->getValue())) {
                    $res .= '<img src="' . $image->getPath() . '" />';
                }
            }
            $res .= '<hr/>';
        }
        return $res;
    }

    public function __render($displayArgs = null) {
        $res = '';

        if (strlen($this->text_field->value)) {
            $res = '<center>';
            $res .= '<div style="width:600px; border:2px solid blue;">';
            $res .= '<h1>' . $this->text_field->value . '</h1>';
            $res .= $this->wysiwyg_field->value;
            $res .= $this->create_combo->value;
            //   $res .= '<img  src="' . config_get('path.public_upload_directory') . $this->image_field->value . '"/>';
            $res .= '</div>';
            $res .= '</center>';
        }
        return $res;
    }

}

?>